<?php
/**
 * ==============================
 * === New Function =============
 * ==============================
 */
if ( function_exists( 'add_theme_support' ) ) {
	add_theme_support( 'post-thumbnails' );
}

//Store comment type meta
function add_custom_comment_field($comment_id){
	add_comment_meta($comment_id, 'comment_type', $_POST['comment_type']);
}
add_action('comment_post', 'add_custom_comment_field');

//Add comment type meta
function add_custom_comment_type_field()
{
	echo '<input type="hidden" name="comment_type" value="is watching" id="comment_type">';
}
add_action('comment_form_top', 'add_custom_comment_type_field');

/**
 * Modified activity action
 */
//apply_filters_ref_array( 'bp_blogs_activity_new_comment_action',       array( $activity_action,  &$recorded_comment, $comment_link ) ),
function modified_activity_action($activity_action,$recorded_comment,$comment_link)
{
	error_log('Aonz - modified_activity_action'.print_r($recorded_comment,true));
// 	$activity_action = $args[0];
// 	$recorded_comment = $args[1];
// 	$comment_link = $args[2];
	
	// Get the user by the comment author email.
	$user = get_user_by( 'email', $recorded_comment->comment_author_email );
	// Get the user_id
	$user_id = (int) $user->ID;
	
	// Get activity related links
	$post_permalink = get_permalink( $recorded_comment->comment_post_ID );
	$comment_link   = htmlspecialchars( get_comment_link( $recorded_comment->comment_ID ) );
	
	$action = "is watching";//TODO Sample action
	
	$result = sprintf( __( '%1$s '.$action.', %2$s', 'buddypress' ), bp_core_get_userlink( $user_id ), '<a href="' . $post_permalink . '">' . apply_filters( 'the_title', $recorded_comment->post->post_title ) . '</a>' );
	error_log('Aonz - modified_activity_action - rsult = '.print_r($result,true));
	return $result;
}
add_filter('bp_blogs_activity_new_comment_action', 'modified_activity_action', 10, 3);
?>





<?php 
/**
 * ==============================
 * ==============================
 * Overrided BuddyPress Functions
 * ==============================
 * ==============================
 */
function bp_dtheme_blog_comments( $comment, $args, $depth ) {
	$GLOBALS['comment'] = $comment;

	if ( 'pingback' == $comment->comment_type )
		return false;

	if ( 1 == $depth )
		$avatar_size = 50;
	else
		$avatar_size = 25;
	?>

	<li <?php comment_class(); ?> id="comment-<?php comment_ID(); ?>">
		<div class="comment-avatar-box">
			<div class="avb">
				<a href="<?php echo get_comment_author_url(); ?>" rel="nofollow">
					<?php if ( $comment->user_id ) : ?>
						<?php echo bp_core_fetch_avatar( array( 'item_id' => $comment->user_id, 'width' => $avatar_size, 'height' => $avatar_size, 'email' => $comment->comment_author_email ) ); ?>
					<?php else : ?>
						<?php echo get_avatar( $comment, $avatar_size ); ?>
					<?php endif; ?>
				</a>
			</div>
		</div>

		<div class="comment-content">
			<div class="comment-meta">
				<p>
					<?php
						/* translators: 1: comment author url, 2: comment author name, 3: comment permalink, 4: comment date/timestamp*/
						printf( __( '<a href="%1$s" rel="nofollow">%2$s</a> shout on <a href="%3$s"><span class="time-since">%4$s</span></a>', 'buddypress' ), get_comment_author_url(), get_comment_author(), get_comment_link(), get_comment_date() );
					?>
				</p>
			</div>

			<div class="comment-entry">
				<?php if ( $comment->comment_approved == '0' ) : ?>
				 	<em class="moderate"><?php _e( 'Your comment is awaiting moderation.', 'buddypress' ); ?></em>
				<?php endif; ?>

				<?php comment_text(); ?>
			</div>

			<div class="comment-options">
					<?php if ( comments_open() ) : ?>
						<?php comment_reply_link( array( 'depth' => $depth, 'max_depth' => $args['max_depth'] ) ); ?>
					<?php endif; ?>

					<?php if ( current_user_can( 'edit_comment', $comment->comment_ID ) ) : ?>
						<?php printf( '<a class="button comment-edit-link bp-secondary-action" href="%1$s" title="%2$s">%3$s</a> ', get_edit_comment_link( $comment->comment_ID ), esc_attr__( 'Edit comment', 'buddypress' ), __( 'Edit', 'buddypress' ) ); ?>
					<?php endif; ?>

			</div>

		</div>
<?php 
}
?>